package com.api.sw.duban.action;

import com.api.sw.duban.util.LogTool;
import weaver.docs.share.DocShareUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.action.BaseAction;

/**
 * 添加流程文档文档共享权限
 */
public class ShareWfdoc extends BaseAction {
    private final static LogTool log1 = new LogTool("/log/duban/",false);
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid=requestInfo.getRequestid();
        int createid=requestInfo.getRequestManager().getCreater();
        log1.writeLog(requestid+"设置文档权限"+requestid+" createid"+createid);
        MainTableInfo mainTableInfo=requestInfo.getMainTableInfo();
        Property[] Property=mainTableInfo.getProperty();
        String docid="";
        String userid="";
        for(Property prop:Property){
            String name=prop.getName();
            String value= Util.null2String(prop.getValue()) ;
            if("scfj".equalsIgnoreCase(name)){
                if(!"".equals(value)){
                    docid=docid+value.trim()+",";
                }
            }
            if("zw".equalsIgnoreCase(name)){
                if(!"".equals(value)){
                    docid=docid+value.trim()+",";
                }
            }
            if("ckry".equalsIgnoreCase(name)){
                if(!"".equals(value)){
                    userid=value.trim();
                }
            }
        }
        log1.writeLog(docid);
        if(!"".equals(docid)&&!"".equals(userid)&&createid>0){
            User user=new User(createid);

            String[] docids=docid.split(",");
            for(String str:docids){
                str=Util.null2String(str).trim() ;
                if(!"".equals(str)){
                    DocShareUtil.addDocShare(user,str,"1",userid,"0","1");
                }
            }
        }
        return super.execute(requestInfo);
    }
}
